var t = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("../../until/storage")), e = getApp(), a = null;

Page({
    data: {
        videoAd: e.globalData.config.adConfig.videoAd,
        val: "",
        list: [],
        ifContent: !1,
        searchLouckConfig: {},
        louck_share: !1,
        history: [],
        hotList: [],
        focus: !0
    },
    changVal: function(t) {
        this.setData({
            val: t.detail.value
        }), "" === this.data.val && this.setData({
            list: [],
            ifContent: !1
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    cleanVal: function() {
        this.setData({
            val: "",
            list: [],
            ifContent: !1
        });
    },
    search: function() {
        var e = this.data.searchLouckConfig, a = e.louckStatus, o = e.expires_timeOut, s = e.louck_num, n = t.default.get("localSearcheNum"), i = this;
        if (this.setData({
            list: []
        }), a) if (n) {
            var c = n += 1;
            if (n == s) return wx.showModal({
                title: "温馨提示",
                content: "分享好友群可以跳过广告直接搜索哦",
                cancelText: "播放广告",
                confirmText: "跳过广告",
                success: function(t) {
                    t.confirm ? (console.log("用户点击跳过广告 进入分享"), i.setData({
                        louck_share: !0
                    })) : t.cancel && (console.log("用户点击观看广告"), i.lookAd());
                },
                fail: function(t) {}
            }), t.default.set("localSearcheNum", c), !1;
            t.default.set("localSearcheNum", c);
        } else t.default.set("localSearcheNum", 1), wx.setStorageSync("localSearcheNum__expires__", Date.now() + 6e4 * o);
        i.searchAxios();
    },
    leaving: function() {
        wx.previewImage({
            current: "http://www.120kg.xyz/static/images/wxMovie/id-card.jpeg",
            urls: [ "http://www.120kg.xyz/static/images/wxMovie/id-card.jpeg" ]
        });
    },
    getDetailConfig: function() {
        var t = e.globalData.config, a = t.showVersion, o = t.sessionVersion, s = this;
        wx.request({
            url: "https://www.120kg.xyz/wxMovieVersion",
            success: function(t) {
                a < +t.data[o].version && s.setData({
                    searchLouckConfig: t.data[o].searchLouckConfig
                });
            }
        });
    },
    shareAd: function() {
        this.setData({
            louck_share: !1
        }), this.lookAd();
    },
    lookAd: function() {
        var t = this;
        try {
            var e = wx.getSystemInfoSync().SDKVersion;
            e = e.replace(/\./g, ""), parseInt(e) >= 260 ? a && a.show().catch(function() {
                a.load().then(function() {
                    return a.show();
                }).catch(function(e) {
                    console.log("激励视频 广告显示失败"), t.showToast("现在可以使用搜索了哦～");
                });
            }) : t.showToast("现在可以使用搜索了哦～");
        } catch (e) {
            t.showToast("现在可以使用搜索了哦～");
        }
    },
    setRewardedVideoAd: function() {
        var o = this;
        wx.createRewardedVideoAd && ((a = wx.createRewardedVideoAd({
            adUnitId: e.globalData.config.adConfig.searchRewardedVideoAd
        })).onLoad(function() {
            console.log("拉取激励广告成功");
        }), a.onError(function(t) {
            console.log("拉取激励广告失败"), o.showToast("现在可以使用搜索了哦～");
        }), a.onClose(function(e) {
            if (e && e.isEnded) console.log("激励广告加载完成"), o.showToast("现在可以使用搜索了哦～"), o.setData({
                focus: !0
            }); else {
                console.log("激励广告被强制关闭");
                var a = t.default.get("localSearcheNum");
                o.showToast("没有看完广告不能使用搜索哦～"), o.setData({
                    focus: !0
                }), t.default.set("localSearcheNum", a - 1);
            }
        }));
    },
    searchAxios: function() {
        var t = this;
        wx.showLoading({
            title: "加载中..."
        }), this.setData({
            ifContent: !1
        }), wx.request({
            url: "https://www.120kg.xyz/search",
            data: {
                name: this.data.val
            },
            method: "POST",
            success: function(e) {
                wx.hideLoading(), t.setData({
                    list: e.data.data
                }), e.data.data.length < 1 && (t.setData({
                    ifContent: !0
                }), t.showToast("未搜索相关内容～")), t.setSearchHistory();
            },
            fail: function(e) {
                t.setData({
                    ifContent: !0
                }), console.error("接口调用失败", e);
            }
        });
    },
    showToast: function(t) {
        var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 3e3;
        wx.showToast({
            title: t,
            duration: e,
            icon: "none"
        });
    },
    bindKeyInput: function(t) {
        console.log(t.detail.value);
    },
    recentSearch: function(t) {
        var e = t.currentTarget.dataset.text;
        this.setData({
            val: e
        }), this.search();
    },
    setSearchHistory: function() {
        var t = this, e = t.data.history, a = e.indexOf(t.data.val);
        -1 != a ? (e.splice(a, 1), e.unshift(t.data.val)) : e.unshift(t.data.val), wx.setStorage({
            key: "history_arr",
            data: e
        }), t.getSearchHistory();
    },
    getSearchHistory: function() {
        var t = this;
        wx.getStorage({
            key: "history_arr",
            success: function(e) {
                console.log(e.data), t.setData({
                    history: e.data
                });
            }
        });
    },
    cleanSearchHistory: function() {
        this.setData({
            history: []
        }), wx.removeStorage({
            key: "history_arr"
        });
    },
    hotSearch: function() {
        var t = this;
        wx.request({
            url: "https://www.120kg.xyz/hotSearch",
            success: function(e) {
                t.setData({
                    hotList: e.data.data || []
                });
            },
            fail: function(t) {
                console.error("接口调用失败", t);
            }
        });
    },
    onLoad: function(t) {
        this.setRewardedVideoAd(), this.hotSearch();
    },
    onReady: function() {},
    onShow: function() {
        this.getDetailConfig(), this.getSearchHistory();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return this.setData({
            louck_share: !1
        }), {
            title: "[有人@你] 邀请您一起看免费电影",
            path: "pages/index/index",
            imageUrl: "",
            success: function(t) {}
        };
    }
});